<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>叩丁狼权限管理系统</title>
    <#include "../common/header.ftl" >
    <script type="text/javascript" src="/jquery/plugins/jquery.form.js"></script>
    <script type="text/javascript" src="/jquery/plugins/jquery.bootstrap.min.js"></script>
    <!--导入日期插件-->
    <script type="text/javascript" src="/jquery/My97DatePicker/WdatePicker.js"></script>
    <style>
        .modal-body img {
            width: 100%;
        }
    </style>
    <script>
        $(function () {
            // 推荐游记按钮
            $(".edit_Btn").click(function () {
                // 获取绑定数据
                var json = $(this).data("json");
                // 回显数据
                console.log(json);
                if (json) {  // 编辑按钮
                    //回显数据
                    $("input[name=id]").val(json.id);
                    $("#editForm input[name=title]").val(json.title);
                    $("input[name=subTitle]").val(json.subTitle);
                    // 将封面回显给用户看
                    $(".coverUrl").attr("src", json.coverUrl);
                    // 将图片回显再input标签
                    $("input[name=coverUrl]").val(json.coverUrl);
                    // 回显推荐的时间
                    $("input[name=schedule]").val(json.schedule);
                    $("select[name=type]").val(json.type);
                    // 设置a连接的地址
                    $(".showTravel").attr("href", '/travels/releaseList.do?travelId=' + json.travelId);
                    $("#commendModal").modal("show");
                }
            })
            // 保存模态框里的数据
            $(".btn-submit").click(function (data) {
                //将表单的提交方式修改为ajax异步提交
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        $.messager.alert("温馨提示", "操作成功!");
                        setTimeout(function () {
                            window.location.reload();
                        }, 500);
                    }
                })
            })

        })
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#assign currentMenu="travelcommends"/>
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐设置管理</h1>
                </div>

                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/travelcommends/list.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}"
                               placeholder="请输入游记标题/副标题">
                    </div>
                    <select id="qo_type" class="form-control" name="type">
                        <option value="-1">全部</option>
                        <option value="1">每周推荐</option>
                        <option value="2">每月推荐</option>
                        <option value="3">攻略推荐</option>
                    </select>
                    <script>
                        $("#qo_type").val("${(qo.type)!}");
                    </script>
                    <input type="submit" id="btn_query" class="btn btn-default btn-success" value="查询">

                </form>
            </div>

            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间安排</th>
                    <th>推荐类型</th>
                </tr>
                </thead>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>
                            <img width="50px" height="50px" src="${(entity.coverUrl)!}">
                        </td>
                        <td>${entity.title}</td>
                        <td>${entity.subTitle}</td>
                        <td>${entity.schedule?string("yyyy-MM-dd")}</td>
                        <td>${(entity.typeName)!}</td>
                        <td>
                            <a href="javascript:;" class="edit_Btn" data-json='${entity.json}'>修改</a>
                        </td>

                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl" />
        </div>
    </div>
</div>
<#--设置推荐模态框-->
<div class="modal fade" id="commendModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增游记推荐</h4>
            </div>
            <div class="modal-body" style="text-align: center;">
                <form class="form-horizontal" action="/travelcommends/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id"><#--记录游记的id-->
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="title" name="title"
                                   placeholder="请输入游记标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="subTitle" name="subTitle"
                                   placeholder="请输入游记副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img width="100%" class="coverUrl"/>
                            <input type="hidden" class="form-control" id="coverUrl" name="coverUrl">
                            <input type="file" class="form-control" id="file" name="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-2 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="schedule" name="schedule"
                                   placeholder="请输选择推荐时间" onclick="WdatePicker()">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-2 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" autocomplete="off" name="type">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center;">
                        <#-- 查看文章时候新打开一个界面 -->
                        <a href="#" class="showTravel" target="_blank">点击查看游记文章内容</a>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
</html>